﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EasyTest {

    /// <summary>
    /// Link object
    /// </summary>
    public class Link : IElement {

        /// <summary>
        /// Create new Link object.
        /// </summary>
        /// <param name="findBy">HTML text to identify and find elements within a document.</param>
        public Link(string findBy) {
            FindBy = findBy;
            Focus = new Focus();
        }

        /// <summary>
        /// Create new Link object.
        /// </summary>
        /// <param name="findBy">HTML text to identify and find elements within a document.</param>
        /// <param name="focus">Document container with controls to search for.</param>
        public Link(string findBy, Focus focus)
            : this(findBy) {
            Focus = focus;
        }

        /// <summary>
        /// Create new Link object.
        /// </summary>
        /// <param name="findBy">HTML text to identify and find elements within a document.</param>
        /// <param name="parent">Parent link this link belongs to.</param>
        public Link(string findBy, Link parent) {
            FindBy = findBy;
            ParentElement = parent;
        }

        /// <summary>
        /// Create new Link object.
        /// </summary>
        /// <param name="findBy">HTML text to identify and find elements within a document.</param>
        /// <param name="focus">Document container with controls to search for.</param>
        /// <param name="parent">Parent link this link belongs to.</param>
        public Link(string findBy, Focus focus, Link parent) {
            FindBy = findBy;
            Focus = focus;
            ParentElement = parent;
        }


        /// <summary>
        /// Set the focus to this Link and if displayed and enabled, click it.
        /// </summary>
        public void Go() {
            if (Browser.ActiveFocus != Focus) {
                Focus.Go(true);
            }
            if (!Action.IsDisplayed(FindBy)) {
                if (!Action.IsDisplayed(FindBy)) {
                    if (ParentElement != null)
                        ParentElement.Click();

                }
            }
            Action.Click(FindBy);
        }
    }
}
